package de.bazinga.rotw.network.message;

import com.captiveimagination.jgn.message.Message;
import com.captiveimagination.jgn.message.type.CertifiedMessage;
import com.captiveimagination.jgn.message.type.PlayerMessage;
import com.captiveimagination.jgn.message.type.TimestampedMessage;
import com.jme.math.Vector3f;

import de.bazinga.rotw.game.RotwGameState;
import de.bazinga.rotw.player.Player;

public class HitMessage extends Message implements CertifiedMessage, PlayerMessage, TimestampedMessage, GameMessage {
	/**
	 * The name of the player who fired the bullet
	 */
	private String playerName = "";
	
	/**
	 * How much damage did it cost?
	 */
	private int damage = 0;

	/**
	 * Take the flags from NewBulletMessage
	 */
	private int weaponFlag = -1;
	
	/**
	 * The Location of the Person who shoot
	 */
	private Vector3f playerLocation = null;

	public String getPlayerName() {
		return playerName;
	}

	public void setPlayerName(String playerName) {
		this.playerName = playerName;
	}

	public void setWeaponFlag(int weaponFlag) {
		this.weaponFlag = weaponFlag;
	}

	public int getWeaponFlag() {
		return weaponFlag;
	}

	public int getDamage() {
		return damage;
	}

	public void setDamage(int damage) {
		this.damage = damage;
	}

	public void setPlayerLocation(Vector3f playerLocation) {
		this.playerLocation = playerLocation;
	}

	public Vector3f getPlayerLocation() {
		return playerLocation;
	}
	
	
	public void handleMessage(RotwGameState game, Message msg, boolean server) {
		if(!(msg instanceof HitMessage)) return ;

		HitMessage message = (HitMessage)msg;
		
		if(server) {
			if(message.getWeaponFlag() == NewBulletMessage.VEHICLE) {
        		// The Player got hit!
        		Player player = game.getPlayer();
        		player.hit(
        				message.getPlayerName(), 
        				message.getDamage(),
        				message.getPlayerLocation());
        	}
		}else{
			
			if(message.getWeaponFlag() == NewBulletMessage.PISTOLGUN || 
					message.getWeaponFlag() == NewBulletMessage.RIFLEGUN || 
					message.getWeaponFlag() == NewBulletMessage.KNIFE || 
					message.getWeaponFlag() == NewBulletMessage.UZI || 
					message.getWeaponFlag() == NewBulletMessage.VEHICLE || 
					message.getWeaponFlag() == NewBulletMessage.HEGRANADE ||
					message.getWeaponFlag() == NewBulletMessage.BASEATTACKER) {
	    		// The Player got hit!
	    		game.getPlayer().hit(
	    				message.getPlayerName(), 
	    				message.getDamage(),
	    				message.getPlayerLocation());
	    	}
		}
	}
}